/*
 * File: exercise1.cpp
 * -------------------
 * endWith function 
 * compile command :
 * g++ -Wall -g exercise1.cpp -o exercise1 -lStanfordCPPLib -I ../include/
 */

#include <iostream>
#include <string>
using namespace std;

bool endsWith(string str, string suffix);
bool endsWith(string str, char suffix);

int main()
{
	string str = "Hello Archlinux";
	string suffix1 = "inux";
	string suffix2 = "abcd";
	char suffix3 = 'x';
	char suffix4 = 'y';
	cout<<"Results: "<<endsWith(str, suffix1)<<endsWith(str, suffix2)<<endsWith(str, suffix3)<<endsWith(str, suffix4)<<endl;
	return 0;
}

bool endsWith(string str, string suffix)
{
	int nchars = suffix.length();
	int start = str.length() - nchars;
	if(start < 0)
		return false;
	for(int i = 0; i < nchars; i++)
	{
		if(str[start + i] != suffix[i])
			return false;
	}
	return true;
}

bool endsWith(string str, char suffix)
{
	return str.length() > 0 && str[str.length() - 1] == suffix;
}
